<?php
class module{
	public $tabs = array();
	public $modules = array();
	public $curModule = array();
	public $curPage;
	public function __CONSTRUCT(){
		global $phprpg, $page, $db;
		foreach(glob(ACP_ROOT."modules/*/module.php") as $moduleFile){
			require_once($moduleFile);
			$module = str_ireplace(ACP_ROOT."modules/","",str_ireplace("/module.php","",$moduleFile));
			$classname = "module_".$module;
			$this->modules[$module] = new $classname;
			$moduleInfo = $this->modules[$module]->info();
			if(!@array_key_exists($moduleInfo['tab_position'],$this->tabs)){
				$this->tabs[$moduleInfo['tab_position']] = array();
			}
			$this->tabs[$moduleInfo['tab_position']][$module] = array('module' => $module,'name' => $moduleInfo['tab_name']);
		}
		if(isset($phprpg->input['module']) && array_key_exists($phprpg->input['module'], $this->modules)){
			$moduleName = $phprpg->input['module'];
		}else{
			$moduleName = 'home';
		}
		$this->curModule['class'] = $this->modules[$moduleName];
		$this->curModule['name'] = $moduleName;
		$moduleInfo = $this->curModule['class']->info();
		$modulePages = $this->curModule['class']->pages();
		if(isset($phprpg->input['page']) && array_key_exists($phprpg->input['page'], $modulePages)){
			$curPage = $phprpg->input['page'];
		}else{
			$curPage = $moduleInfo['default_page'];
		}
		$pageFile = ACP_ROOT."modules/{$moduleName}/{$modulePages[$curPage]}";
		$this->curPage = $pageFile;
	}
}
?>